/**
 * PeriodType.java 
 * Copyright © 2015-3015, 杭州泊享网络科技有限公司
 * 
 * @author Liu Tao
 * @create 2015年2月5日
 */
package com.pshare.enums;

import java.util.HashMap;
import java.util.Map;

import com.pshare.constant.SeaxConstants;

/**
 * 周期类型
 */
public enum PeriodType {
	
	DAY(1, "DAY", "日"), 
	WEEK(2, "WEEK", "周"), 
	MONTH(3, "MONTH", "月"), 
	QUARTER(4, "QUARTER", "季度"), 
	YEAR(5, "YEAR", "年"),
	ALL(6, "ALL", "总");

	private Integer code;
	private String value;
	private String name;

	private PeriodType(Integer code, String value, String name) {
		this.code = code;
		this.value = value;
		this.name = name;
	}

	public Integer getCode() {
		return code;
	}

	public void setCode(Integer code) {
		this.code = code;
	}

	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
	
	public static Boolean codeOf(Integer code) {
		for (PeriodType commonEnum : PeriodType.values()) {
			if (new Integer(commonEnum.getCode()).equals(code)) {
				return true;
			}
		}
		return false;
	}
	
	public static String getValue(int code) {
		for (PeriodType em : PeriodType.values()) {
			if (em.getCode() == code) {
				return em.getValue();
			}
		}
		return SeaxConstants.EMPTY;
	}
	
	public static String getName(int code) {
		for (PeriodType em : PeriodType.values()) {
			if (em.getCode() == code) {
				return em.getName();
			}
		}
		return SeaxConstants.EMPTY;
	}
	
	public static Map<Integer, String> getAll() {
		Map<Integer, String> map = new HashMap<Integer, String>();
		for (PeriodType em : PeriodType.values()) {
			Integer code = em.getCode();
			map.put(code, em.getName(code));
		}
		return map;
	}
}
